//
//  QZAnnotationView.m
//  map
//
//  Created by 000 on 16/8/1.
//  Copyright © 2016年 faner. All rights reserved.
//

#import "QZAnnotationView.h"
//#import "QZLeftPopVC.h"
//#import "MapVC.h"


@interface QZAnnotationView ()

//@property (nonatomic, strong) NSMutableArray *mArray;
//@property (nonatomic, strong) MapVC *mapVC;


@end

@implementation QZAnnotationView

//- (MapVC *)mapVC
//{
//    if (_mapVC == nil) {
//        _mapVC = [[MapVC alloc] init];
//    }
//    return _mapVC;
//}

//- (NSMutableArray *)mArray
//{
//    if (_mArray == nil) {
//        _mArray = [NSMutableArray array];
//    }
//    return _mArray;
//}

//左侧图片的更换
- (UIButton *)leftButton
{
    if (_leftButton == nil) {
        _leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _leftButton.frame = CGRectMake(0, 0, 30, 30);
        [_leftButton setBackgroundImage:[UIImage imageNamed:@"add"] forState:UIControlStateNormal];
        [_leftButton addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftButton;
}

- (UIButton *)rightButton
{
    if (_rightButton == nil) {
        _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _rightButton.frame = CGRectMake(0, 0, 30, 30);
        [_rightButton setBackgroundImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
        [_rightButton addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightButton;
}

//气泡中详细的label
- (UIButton *)downBtn
{
    if (_downBtn ==nil) {
        _downBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _downBtn.frame = CGRectMake(0, 0, 100, 30);
        _downBtn.backgroundColor = [UIColor redColor];
        [_downBtn setTitle:@"哈哈" forState:UIControlStateNormal];
        [_downBtn addTarget:self action:@selector(downBtnClick)
           forControlEvents:UIControlEventTouchUpInside];
    }
    return _downBtn;
}



+ (QZAnnotationView *)getQZAnnotationViewWithMapView:(MKMapView *)mapView andAnnotation:(id<MKAnnotation>)annotation
{
    static NSString *pinIdentifier = @"pinIdentifier";
    QZAnnotationView *pin = (QZAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pinIdentifier];
    if (pin ==nil) {
        pin = [[QZAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pinIdentifier];
        //设置是否弹出标注
        pin.canShowCallout = YES;
        //设置大头针可以拖拽
//        pin.draggable = YES;
        
        pin.leftCalloutAccessoryView = pin.leftButton;
        
//        pin.rightCalloutAccessoryView = pin.rightButton;
        
        pin.detailCalloutAccessoryView = pin.downBtn;
        
        pin.string = @"desk";
        
        [pin.downBtn setTitle:annotation.subtitle forState:UIControlStateNormal];
    }
    
    pin.annotation = annotation;
    
    return pin;
}

- (void)downBtnClick
{
    [self.delegate annotationView:self downBtnClickWith:(QZAnnotation*)self.annotation];
}
- (void)leftBtnClick
{
    [self.delegate annotationView:self leftBtnClickWith:(QZAnnotation*)self.annotation];
}
- (void)rightBtnClick
{
    [self.delegate annotationView:self rightBtnClickWith:(QZAnnotation*)self.annotation];
}
@end
